APP_NAME = dwqlmxcx
APP_PATH = ./cmd/

# build dist
BUILD_PATH := ./dist

# params
GO_FLAGS = -ldflags "-s -w" -trimpath -tags netgo

# Go build fn 1-GOOS 2-GOARCH 3-FILE EXT
define go/build
	GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build $(GO_FLAGS) -o $(BUILD_PATH)/$(APP_NAME)-$(1)-$(2)-latest$(3) ${APP_PATH}
endef

# PHONY
.PHONY: darwin linux windows

darwin:
	$(call go/build,darwin,amd64)

linux:
	$(call go/build,linux,amd64)

windows:
	$(call go/build,windows,amd64,.exe)

linux64:
	$(call go/build,linux,amd64)

publish: linux
	@echo "publish~"
	ssh root@47.107.44.52 'sudo rm -f /www/dwqlmxcx/dwqlmxcx-linux-amd64-latest'
	scp -r $(BUILD_PATH)/dwqlmxcx-linux-amd64-latest root@47.107.44.52:/www/dwqlmxcx/
	ssh root@47.107.44.52 'sudo chmod a+x /www/dwqlmxcx/dwqlmxcx-linux-amd64-latest && sudo systemctl restart dwqlmxcx.service'